/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Modelo;

import Controlador.Conection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author JUANCHO
 */
public class ClsAdministradorHotel {

    private String doc_client;
    private String fname_client;
    private String sname_client;
    private String flname_client;
    private String slname_client;
    private String dbirth_client;
    private String email_client;
    private String password;
    //las siguientes variables son para pagos
    private String id_pago;
    private String fechapago;
    private String saldo;
    private String estado;
    private Conection conn = new Conection();
    private Controlador.Conection cnn = new Controlador.Conection();

    public ClsAdministradorHotel() {
    }

    public ClsAdministradorHotel(String doc_client, String fname_client, String sname_client, String flname_client, String slname_client, String dbirth_client, String email_client, String password, String id_pago, String fechapago, String saldo, String estado) {
        this.doc_client = doc_client;
        this.fname_client = fname_client;
        this.sname_client = sname_client;
        this.flname_client = flname_client;
        this.slname_client = slname_client;
        this.dbirth_client = dbirth_client;
        this.email_client = email_client;
        this.password = password;
        this.id_pago = id_pago;
        this.fechapago = fechapago;
        this.saldo = saldo;
        this.estado = estado;
    }

    public String insertarPago(String doc_client, String vSaldo, String fechapago, String estado) {
        if (verifica(doc_client) == true) {
            int saldo = Integer.parseInt(consultarSaldo(doc_client)) + Integer.parseInt(vSaldo);
            String sql = "UPDATE tblpagos SET  fechapago='" + fechapago + "', saldo='" + saldo + "' where doc_client='" + doc_client + "'";
            if (getCnn().actualizar(sql) == 1) {
                return "0";
            } else {
                return "-1";
            }
        } else {

            String sql = "INSERT INTO tblpagos VALUES ('" + null + "', '" + doc_client + "', '" + fechapago + "','" + vSaldo + "''" + estado + "')";
            if (getCnn().insertar(sql) == null) {
                return "1";
            }

            return "-1";
        }
    }

    public boolean verifica(String eldatoabuscar) {//
        String sql = "SELECT * from tblpagos where doc_client = '" + eldatoabuscar.toString() + "'";
        if (getCnn().verificar(sql) == 1) {
            return true;
        }
        return false;
    }

    public String consultarSaldo(String doc_client) {
        String resultado = "";
        try {
            //
            String sql = "SELECT saldo From tblpagos where doc_client='" + doc_client.toString() + "'";

            ResultSet rs = null;
            rs = getCnn().consultar(sql);
            if (rs.next()) {
                resultado = rs.getString(1);
            } else {
                resultado = "0";
            }

        } catch (SQLException ex) {
            Logger.getLogger(ClsPagos.class.getName()).log(Level.SEVERE, null, ex);
        }
        return resultado;
    }

    public String consultar_Doc_Client(String email_client) {
        String resultado = "";
        try {
            //
            String sql = "SELECT doc_client From tblclients where email_client='" + email_client.toString() + "'";

            ResultSet rs = null;
            rs = getCnn().consultar(sql);
            if (rs.next()) {
                resultado = rs.getString(1);
            } else {
                resultado = "0";
            }

        } catch (SQLException ex) {
            Logger.getLogger(ClsPagos.class.getName()).log(Level.SEVERE, null, ex);
        }
        return resultado;
    }

    public String getDoc_client() {
        return doc_client;
    }

    public void setDoc_client(String doc_client) {
        this.doc_client = doc_client;
    }

    public String getFname_client() {
        return fname_client;
    }

    public void setFname_client(String fname_client) {
        this.fname_client = fname_client;
    }

    public String getSname_client() {
        return sname_client;
    }

    public void setSname_client(String sname_client) {
        this.sname_client = sname_client;
    }

    public String getFlname_client() {
        return flname_client;
    }

    public void setFlname_client(String flname_client) {
        this.flname_client = flname_client;
    }

    public String getSlname_client() {
        return slname_client;
    }

    public void setSlname_client(String slname_client) {
        this.slname_client = slname_client;
    }

    public String getDbirth_client() {
        return dbirth_client;
    }

    public void setDbirth_client(String dbirth_client) {
        this.dbirth_client = dbirth_client;
    }

    public String getEmail_client() {
        return email_client;
    }

    public void setEmail_client(String email_client) {
        this.email_client = email_client;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getId_pago() {
        return id_pago;
    }

    public void setId_pago(String id_pago) {
        this.id_pago = id_pago;
    }

    public String getFechapago() {
        return fechapago;
    }

    public void setFechapago(String fechapago) {
        this.fechapago = fechapago;
    }

    public String getSaldo() {
        return saldo;
    }

    public void setSaldo(String saldo) {
        this.saldo = saldo;
    }

    public String getEstado() {
        return estado;
    }

    public void setEstado(String estado) {
        this.estado = estado;
    }

    public Conection getConn() {
        return conn;
    }

    public void setConn(Conection conn) {
        this.conn = conn;
    }

    public Conection getCnn() {
        return cnn;
    }

    public void setCnn(Conection cnn) {
        this.cnn = cnn;
    }
}
